package com.ytjj.qmyx.admin.controller.function;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.client.DataClient;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.dto.YxFunctionConfigNewuserDto;
import com.ytjj.qmyx.admin.model.request.MessageRequest;
import com.ytjj.qmyx.admin.model.request.OrientAdvertRequest;
import com.ytjj.qmyx.admin.service.function.FunctionConfigService;
import com.ytjj.qmyx.admin.service.function.FunctionConfigUserService;
import com.ytjj.qmyx.mall.model.YxFunctionConfig;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/function")
public class FunctionController {

    @Resource
    private FunctionConfigService functionConfigService;

    @Resource
    private FunctionConfigUserService functionConfigUserService;

    @Resource
    private DataClient dataClient;

    @PostMapping("/queryPage")
    public CommonResult<CommonPage<YxFunctionConfig>> queryPage(@RequestBody OrientAdvertRequest param) {
        return CommonResult.success(functionConfigService.queryPage(param));
    }

//    @GetMapping("/getDetailById/{id}")
//    public CommonResult<YxFunctionConfigNewuserDto> getDetailById(@PathVariable Integer id) {
//        return CommonResult.success(functionConfigUserService.getDetailById(id));
//    }

    @GetMapping("/getDetailById/{id}")
    public CommonResult<Map> getDetail(@PathVariable Integer id) {
        return CommonResult.success(functionConfigUserService.getDetail(id));
    }


    @PostMapping("/update")
    @OperLog(operModule = "功能配置表", operDesc = "编辑功能配置表", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult update(@RequestBody  YxFunctionConfigNewuserDto param) {
        Assert.notNull(param.getConfigId(), "id不能为空!");
        functionConfigUserService.update(param);
        return CommonResult.success();
    }

    @PostMapping("/reSendMsg")
    public CommonResult reSendMsg(@RequestBody MessageRequest request){
        CommonResult commonResult = dataClient.reSendMsg(request);
        return CommonResult.success(commonResult);
    }

}
